﻿#region Using

using Common.Base;
using Common.Enums;

using GameCommon.ManagerInterfaces;

using Microsoft.Xna.Framework.Graphics;

using Xna = Microsoft.Xna.Framework;

using GlobalServices = GameCommon.Services.Service;

#endregion

namespace Menu.Components
{
    internal class Texture : MenuComponentBase
    {
        public Texture(string id, Texture2D texture2D)
            : base(id)
        {
            this.Texture2D = texture2D;
            this.Dimension = new Dimension(new Size(this.Texture2D.Width, this.Texture2D.Height));
        }

        public Texture(string id, MenuComponentBase objectToCopy, Texture2D texture2D)
            : base(id)
        {
            this.Texture2D = texture2D;
            this.Dimension = new Dimension(new Size(this.Texture2D.Width, this.Texture2D.Height));
            this.Copy(objectToCopy);
        }

        public Texture2D Texture2D { get; private set; }

        public HorizontalAlignment HorizontalAlignment { get; set; }

        public VerticalAlignment VerticalAlignment { get; set; }

        public override void Draw(IDrawingManager manager, Xna.GameTime gameTime)
        {
            this.DrawingService.Draw(manager, this.Texture2D, this.Dimension, this.Opacity, 1);
        }

        public override void Settle()
        {
            base.Settle();

            this.Dimension = new Dimension(this.Parent.Position.X, this.Parent.Position.Y, this.Dimension.Width, this.Dimension.Height);
            GlobalServices.ComponentModifier.ApplyAlignments(this.Dimension, this.Parent.Dimension, this.Offset, this.HorizontalAlignment, this.VerticalAlignment);
        }

        public override string ToString()
        {
            return string.Format("Texture, Id: {0}", this.Id);
        }
    }
}